package org.se.scut.pinterest.mina.utils;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.List;

public class ListUtils<T> {

	public void copyList(List<T> des, List<T> src){
		
		for (T t : src) {
			T t2 = (T) deepCopy(t);
			des.add(t2);
		}
	}
	
	private T deepCopy( T t){
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		ObjectOutputStream objectOutputStream;
		try {
			objectOutputStream = new ObjectOutputStream(out);
			objectOutputStream.writeObject(t);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		T t2 = null;
		ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
		ObjectInputStream objectInputStream;
		try {
			objectInputStream = new ObjectInputStream(in);
			t2 = (T) objectInputStream.readObject();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return t2;
		
	}
	
}
